package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.OneGouModle;
import com.tiantianyuegou.model.QiangGouModel;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 抢购记录适配器
 * Created by George on 2016/9/18.
 */
public class QiangGouAdapter extends BaseAdapter {
    private Context context;
    private List<QiangGouModel> data;


    public QiangGouAdapter(Context context) {
        this.context = context;
        data=new ArrayList<>();
    }

    public QiangGouAdapter(Context context, List<QiangGouModel> data) {
        this.context = context;
        this.data = data;
    }
    public void setData(List<QiangGouModel> data){
        this.data.clear();
        this.data.addAll(data);
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.item_onegou,null);
            vh = new ViewHolder();
            vh.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            vh.tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
            vh.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
//        获取数据并展示到页面上
        QiangGouModel modle = data.get(position);
        vh.tv_name.setText(modle.getGouName());
        vh.tv_phone.setText(modle.getMobile());

        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        String time = dateFormat.format(modle.getTime());
        vh.tv_time.setText(time);

        return convertView;
    }
    class ViewHolder{
        TextView tv_name;
        TextView tv_phone;
        TextView tv_time;
    }
}
